import { InfoCrudMixin } from 'lin-mizar';
import { merge } from 'lodash';
import { Sequelize, Model } from 'sequelize';
import sequelize from '../lib/db';

class Content extends Model {
  toJSON () {
    const origin = {
      id: this.id,
      title: this.title,
      description: this.description,
      keywords: this.keywords,
      cover: this.cover
    };
    return origin;
  }
}

Content.init(
  {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    title: {
      type: Sequelize.STRING(255),
      allowNull: false
    },
    keywords: {
      type: Sequelize.STRING(30),
      allowNull: true,
      defaultValue: ''
    },
    description: {
      type: Sequelize.STRING(255),
      allowNull: true
    },
    cover: {
      type: Sequelize.STRING(255),
      allowNull: true
    }
  },
  merge(
    {
      sequelize,
      tableName: 'content',
      modelName: 'content',
      timestamps: false
    },
    InfoCrudMixin.options
  )
);

export { Content };
